package tiepbm.app.store.activity;

import java.util.ArrayList;
import java.util.List;

import tiepbm.app.connect.resfulwebservice.WebserviceConnect;
import tiepbm.app.store.fragment.FragmentCategory;
import tiepbm.app.store.object.Obj_Category;
import tiepbm.app.util.lazyLoader.ImageLoader_nghiank;

import com.viewpagerindicator.TabPageIndicator;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

public class HomeActivity extends BaseFragment implements IScreen {
	private List<Obj_Category> mListCategory;
	private ViewPager pager;
	private TabPageIndicator indicator;
	private FragmentPagerAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		initBase();
		initView();
		fillData();
		implementListener();
//		 WebserviceConnect mConnect = new WebserviceConnect();
//		 
//		 List<CategoryDto> mListCategory1 = mConnect.getCategory();
//		 int i;
//		 for(i=0;i<mListCategory1.size();i++){
//			 System.out.println(mListCategory1.get(i).getName());
//		 }
		// mConnect.userLogin("d", "123456");
		// mConnect.registerUser(new UserRegisterDto("tiep", "t@mail.com",
		// "84919441082", "123456", 0));

		adapter = new GoogleMusicAdapter(getSupportFragmentManager());
		pager.setAdapter(adapter);
		indicator.setViewPager(pager);
	}

	class GoogleMusicAdapter extends FragmentPagerAdapter {
		public GoogleMusicAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			return FragmentCategory.newInstance(mListCategory.get(position)
					.getName());
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return mListCategory.get(position).getName().toUpperCase();
		}

		@Override
		public int getCount() {
			return mListCategory.size();
		}
	}

	@Override
	public void initView() {
		// TODO Auto-generated method stub
		pager = (ViewPager) findViewById(R.id.pager);
		indicator = (TabPageIndicator) findViewById(R.id.indicator);
	}

	@Override
	public void implementListener() {
		// TODO Auto-generated method stub

	}

	@Override
	public void fillData() {
		// TODO Auto-generated method stub
		mListCategory = new ArrayList<Obj_Category>();
		mListCategory.add(new Obj_Category(0, "trang chu"));
		mListCategory.add(new Obj_Category(1, "Moi nhat"));
		mListCategory.add(new Obj_Category(2, "Hot nhat"));
		mListCategory.add(new Obj_Category(3, "Pho bien nhat"));
	}
}